package com.puboot.module.service.impl;

import com.puboot.module.model.LkChapterLang;
import com.puboot.module.mapper.LkChapterLangMapper;
import com.puboot.module.service.LkChapterLangService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;


/**
 * (LkChapterLang)表服务实现类
 *
 * @author Leonidax
 * @since 2024-10-14 11:49:30
 */
@Service
@AllArgsConstructor
public class LkChapterLangServiceImpl extends ServiceImpl<LkChapterLangMapper,LkChapterLang> implements LkChapterLangService {
    
    private final LkChapterLangMapper lkChapterLangMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param chapterId 主键
     * @param lang 语言
     * @return 实例对象
     */
    @Override
    public LkChapterLang queryByChapterId(Integer chapterId, String lang) {
        return lkChapterLangMapper.queryByChapterId(chapterId, lang);
    }

    /**
     * 分页查询
     *
     * @param lkChapterLang 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<LkChapterLang> queryByPage(LkChapterLang lkChapterLang, PageRequest pageRequest) {
        long total = lkChapterLangMapper.count(lkChapterLang);
        return new PageImpl<>(lkChapterLangMapper.queryAllByLimit(lkChapterLang, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param lkChapterLang 实例对象
     * @return 实例对象
     */
    @Override
    public LkChapterLang insert(LkChapterLang lkChapterLang) {
        this.lkChapterLangMapper.save(lkChapterLang);
        return lkChapterLang;
    }

    /**
     * 修改数据
     *
     * @param lkChapterLang 实例对象
     * @return 实例对象
     */
    @Override
    public void update(LkChapterLang lkChapterLang) {
        this.lkChapterLangMapper.update(lkChapterLang);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.lkChapterLangMapper.deleteById(id) > 0;
    }
}
